//
//  JDActionContentCell.swift
//  funcode
//
//  Created by Wan Jiading on 2017/2/22.
//  Copyright © 2017年 WanJiading. All rights reserved.
//

import UIKit

class JDActionContentCell: UITableViewCell {

	@IBOutlet weak var titleLabel: UILabel!
	
	@IBOutlet weak var audioTypeLabel: UILabel!
	
	@IBOutlet weak var tryListenLabel: UILabel!
	
	@IBOutlet weak var audioTypeRight: NSLayoutConstraint!

	@IBOutlet weak var tryListenRight: NSLayoutConstraint!
	
	@IBOutlet weak var audioTypeWidth: NSLayoutConstraint!
	
	let ScreenWidth: CGFloat = UIScreen.main.bounds.size.width
	var book: Book? {
		didSet {
			if book!.available_play == "1" {
				tryListenRight.constant = 0
				tryListenLabel.isHidden = true
				audioTypeRight.constant = 15
			} else {
				tryListenRight.constant = 15
				tryListenLabel.isHidden = false
				audioTypeRight.constant = 55
			}
			
			titleLabel.text = book!.book_name
			audioTypeLabel.text = "- \(book!.audio!.audio_type_name!)"
			audioTypeLabel.sizeToFit()
			audioTypeWidth.constant = audioTypeLabel.bounds.size.width
		}
	}
	
	
	func didSelected(_ selected: Bool) {
		let selectedColor = selected ? UIColor.rgb("87a740") : UIColor.rgb("333333")
		self.titleLabel.textColor = selectedColor
		self.audioTypeLabel.textColor = selectedColor
	}
	
	
    override func awakeFromNib() {
        super.awakeFromNib()
		
		self.tryListenLabel.layer.borderWidth = 1.0 / UIScreen.main.scale
		self.tryListenLabel.layer.borderColor = UIColor.rgb("999999").cgColor
		self.tryListenLabel.layer.cornerRadius = 2
		
    }
		

}
